﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ObligorOrganisation", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ObligorOrganisation))]
    public class ObligorOrganisationSerializer : global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ObligorSerializer {
        
        public ObligorOrganisationSerializer(IObligorOrganisation clazz) : 
                base(clazz) {
        }
        
        protected new IObligorOrganisation clazz {
            get {
                return ((IObligorOrganisation)(base.clazz));
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Organisation");
            if (clazz.Organisation!=null) {
                global::Xtee.Core.SerializationMetadata metaOrganisation = this.GetMetaData(clazz.Organisation);
                Writer.WriteTypeAttribute(metaOrganisation.TypeQualifiedName.Namespace, metaOrganisation.TypeQualifiedName.Name);
                metaOrganisation.NewSerializer(clazz.Organisation).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Organisation");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Organisation") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ObligorOrganisation>Organisation");
                }
                global::Xtee.Core.SerializationMetadata metaOrganisation = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IOrganisation>(Reader, "Organisation", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.Organisation = metaOrganisation.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IOrganisation>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Organisation");
                    metaOrganisation.NewSerializer(clazz.Organisation).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ObligorOrganisation>Organisation", Reader.LocalName);
            }
        }
    }
}
